Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3.4k views
in .NET FTP by (160 points)
I am able to transfer (put) any file in the current working directory to the server but I really need to put a file which exists in an alternate directory and have hit the stone wall hard on how to accomplish this.

My basic working code snip:
FTPClient ftp = new FTPClient();
string myZip = "XYZ.zip";
try
{
ftp.Login(Username, Password);
ftp.ConnectMode = FTPConnectMode.PASV;
ftp.TransferType = FTPTransferType.BINARY;

ftp.Put(myZipFile, myZipFile);

}

The XYZ.zip file actually resides in a folder called "E:\Uploads\". Maybe I can not see the forest for the trees but how do I change the Working Directory so I can send the files without moving them first. Is there a way? I found the ChangeWorkingDirectory(dirname) method but for the life of me, can not work out how to use it.

Thank you in advance for your input and my embarrasment is now pre-exposed :oops:

-greg

2 Answers

0 votes
by (162k points)
You need to find out where that directory is on the FTP server. Generally, FTP servers set up a virtual directory structure. It is unlikely your target directory is E:\Uploads (although the name should be the same).

Try logging in with FileZilla or a command line client, and navigate around until you find the directory you are after. Then simply replicate the results of the navigation using ChangeWorkingDirectory (e.g. ChangeWorkingDirectory("..") will move you to the parent).
0 votes
by (160 points)
I knew if I looked behind enough trees I would eventually find the forest only to realize I was in the center of it all along. A good Nap didn't hurt either...

The original question was maybe not clear enough. I had no issue with the FTP server end. I was however unable to pull files from the specified folder on the local system. I have since figured out the answer. It seems that I was trying to make this an FTP issue and was overly focused on solving it through the FTP component when in reality it was a windows directory issue. I have included the updated code below...

Just goes to show that when you are stuck, take a nap... The answer will be crystal clear...

private void button1_Click(object sender, EventArgs e)
{
FTPClient ftp = new FTPClient(HostName);
string myZip = "717_20060411.zip";
try
{
ftp.Login(Username, Password);
ftp.ConnectMode = FTPConnectMode.PASV;
ftp.TransferType = FTPTransferType.BINARY;
System.IO.Directory.SetCurrentDirectory(ArchiveFolder);

ftp.Put(myZip, myZip);

}
catch (Exception ex)
{
MessageBox.Show("Transfer Error: " + ex);
}
finally
{
ftp.Quit();
}
}

I hope this can help others on the same quest of sleepless perfection...

<grin>
-greg

Categories

...