• 用ftpsupport建立所有ftp服务器上不存在的目录


    最近项目中用ftpsupport.dll进行ftp上传,当用户上传文件时如果目录不存在则建立该目录,但是
    现在的问题是用户传来的目录有几层都是不存在的,这样就需要循环建立所有不存在的目录,
    比如需要上传文件到目录/vagerent/temp/a1/a2,但是/temp/a1/a2三个目录都没有建立。
    方法如下:
            /// <summary>
            
    /// 检测ftp上是否有该目录,如果没有则建立
            
    /// </summary>
            
    /// <param name="ip"></param>
            
    /// <param name="name"></param>
            
    /// <param name="psw"></param>
            
    /// <param name="dr">形如/ftproot/dir2/dir2_2/dirlast</param>
            
    /// <returns></returns>

            private void FtpMakeAllDir(string ip,string name,string psw,string dr)
            
    {
                FtpConnection ftp 
    = new FtpConnection();
                ftp.Connect(ip,name,psw);

                
    string [] dir = dr.Split('/');
                
    string curDir = "/";
                
    for (int i = 0;i<dir.Length;i++)
                
    {
                    curDir 
    += "/"+dir[i];
                    
    if (!ftp.DirectoryExist(curDir))
                    
    {
                        
    try
                        
    {
                            ftp.CreateDirectory(curDir);
                        }

                        
    catch{}
                    }

                }

                ftp.Close();
            }

    关于ftpsupport.dll下载和使用的问题请看另一篇blog:
    用ftpsupport进行ftp上传
  • 相关阅读:
    java
    MVC4重复提交数据
    cache
    Nosql
    MVC4重复提交
    PHP Java
    .net performance
    How the Runtime Locates Assemblies
    android
    window.onscroll
  • 原文地址:https://www.cnblogs.com/vagerent/p/807342.html
Copyright © 2020-2023  润新知