Click here to Skip to main content
16,020,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using ftplib for uploading files on ftp server using following code

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


C#
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 mutiple directories and file on ftp server
Posted

This isn't going to work. You cannot treat an FTP server like is was a locally attached file system. You have to extract the .ZIP file locally, then upload the resulting files to where they are supposed to be one-by-one.
 
Share this answer
 
Comments
askquez 10-Apr-13 7:37am    
can i do this by using webservice?
Dave Kreskowiak 10-Apr-13 8:05am    
Only if it has local file system access to the FTP server. It's the ZIP operations that cannot be used over FTP.
Hi,

To unzip files there is a system dll called "Shell32.dll" which you can find in the location "C:\WINDOWS\system32\shell32.dll" (for 32-bit systems). Add a reference of this to your application and follow the coding like the below links.

http://prateektiwari.wordpress.com/2011/08/10/zip-and-unzip-files-using-shell-32-component/[^]

Easily zip / unzip files using Windows Shell32[^]

Happy coding :)

Regards,
Manoj
 
Share this answer
 
Comments
askquez 10-Apr-13 8:14am    
How can i do this on ftp server?
Dave Kreskowiak 10-Apr-13 9:45am    
You can't. The same problem exists that the file operations must be done on a locally attached volumn. They do not work acrossed a protocol boundry like FTP or HTTP.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900