+1 vote

Hi,

My code below for testing ftp connection

using (Ftp ftp = new Ftp())
{
    ftp.Progress += Ftp_Progress;
    string add = txtaddS1.Text;
    string user = txtuserS1.Text;
    string pass = txtpassS1.Text;

    ftp.Connect(add);
    ftp.Login(user, pass);

    ftp.Upload(@"testconnection.txt", @"testconnection.txt");

    ftp.Close();
}

With my direct ftp address: xx.xxx.xxx.xx it worked
But with subfolder xx.xxx.xxx.xx/yy it did not work

Please advise

by (930 points)

1 Answer

+1 vote
 
Best answer

To change folder simply use Ftp.ChangeFolder method:

ftp.Connect(add);
ftp.Login(user, pass);

ftp.ChangeFolder("uploads");

ftp.Upload(@"testconnection.txt", @"testconnection.txt");

ftp.Close();
by (301k points)
selected by

"upload" should be subfolder yy or all path to the folder?

Most servers allow multiple sub folders to be specified e.g. "folder/subfolder1/subfolder2".

So, firstly, we have to connect with ftp server directly to server address (such as IP), after that, we use ftp.ChangeFolder to direct to the folder we want in that server?

It work!
Thanks so much!

Correct. You can also upload to the folder directly:

ftp.Upload(@"folder/sub1/sub2/test.txt", @"test.txt");
...