Reputation:
Hello my final target will be to write a program to send files through sftp to ax external server.
In order to understand I decided before to go through ftp working with Filezilla server. So my idea was writing a client uploading the file C:\temp\Test\AAA\aaa.txt ---> to filezilla server and from here directly down to filesystem in another location. Is this reasoning valid or do I need a remote server space?
Hoping that this works I have tried to implement it using FileZilla Server and writing the client.
using (WebClient client = new WebClient())
{
// open connection with connection-strings
client.Credentials = new NetworkCredential("User1", "Password1");
// upload zip-file on server
client.UploadFile("ftp://localhost/C:/Temp/Test/BBB.txt" + "", WebRequestMethods.Ftp.UploadFile, "C:\\temp\\Test\\AAA.txt");
}
The problem is that when I run the code I get
System.Net.WebException: 'The remote server returned an error: (550) File unavailable (e.g., file not found, no access).'
I understand I am confused but I have not found any example of both client and server on the same computer.
Thanks
---ADD--- Following Chris Berlin's request I noticed that Filezilla reacts to the request by showing this
so the problem really is related to the wrong path
Upvotes: -1
Views: 351
Reputation: 2593
Actually I never got to work on localhost.
You can try that code that works but my hint as said is to work on a remote site:
string myFile = @"C:\temp\Test\aaa.txt";
string strAddress = "ftp://ipAddress:21/TestRemoteFolder/bbb.txt";
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(strAddress);
request.Credentials = new NetworkCredential("myLogin","mypwd");
request.Method = WebRequestMethods.Ftp.UploadFile;
using (Stream fileStream = System.IO.File.OpenRead(myFile))
using (Stream ftpStream = request.GetRequestStream())
{
fileStream.CopyTo(ftpStream);
}
Upvotes: -1