2

I am using ftplib for uploading files on ftp server using following code

FtpConnection ftp = new FtpConnection(serverip, ftpuser, ftppassword);
ftp.Open();
ftp.Login();
ftp.SetCurrentDirectory("domain/wwwroot");

    void CreateDirOnFtp(string sDir, FtpConnection ftp)
            {
                try
                {
                    foreach (string f in Directory.GetFiles(sDir))
                    {
                        Uri uri = new Uri(f);
                        ftp.PutFile(f, System.IO.Path.GetFileName(uri.LocalPath));
                    }

                    foreach (string d in Directory.GetDirectories(sDir))
                    {
                        string dirname = new DirectoryInfo(d).Name;

                        if (!ftp.DirectoryExists(dirname))
                        {
                            ftp.CreateDirectory(dirname);
                        }

                        ftp.SetCurrentDirectory(dirname);
                        CreateDirOnFtp(d, ftp);
                    }
                }
                catch (System.Exception e)
                {
                }

            }

But this code is not iterating through all directories so missing some directories and files on ftp server.

so i decided to upload zip file on ftp and extract it on ftp server but I cant find any way to extract file which exist on ftp server.

How can i do this? Or any other better way to upload multiple directories and file on ftp server

Shoaib Ijaz
  • 5,347
  • 12
  • 56
  • 84

2 Answers2

0

You cant tell sever to extract file using FTP protocol. To do that, you would need to create some web-service that will extract it after upload, or some scheduled task that will extract all the zips it find.

And if you would create a web service, then FTP uploading can be ditched altogether. Service method can accept zipped content and extract it on the server side.

alex
  • 12,464
  • 3
  • 46
  • 67
0

Try recursively go through your directory and upload it via ftp. I think this is much simpler than unzip a file on the server without a webservice.

Community
  • 1
  • 1
Sir l33tname
  • 4,026
  • 6
  • 38
  • 49