简体   繁体   中英

c# FTP to FileZilla Server file name save issue

Whenever I use this code it uploads the jpeg, but the jpegs name is STOR with no extension on the server.

Any idea as to why this happens or how I change the file name when saving from my C# desktop application to my FileZilla FTP Server??

Here is the basic code, the names have been changes to protect the innocent ;)

WebClient client = new WebClient();
client.Credentials = new NetworkCredential("username", "password");
client.BaseAddress = "ftp://mysite.com";
client.UploadFile(WebRequestMethods.Ftp.UploadFile, "C:\mypics\pic1.jpg");

@sgmoore answered the question. You need just use method correctly:

client.UploadFile("pic1.jpg", "C:\mypics\pic1.jpg");

first argument is remote file name, second is path to local file.

You can also try some other ftp client implementations in .net (anyway FTP is implemented badly in .NET standard library), I've used ftplib and it's working good.

Try

client.UploadFile(remoteName, WebRequestMethods.Ftp.UploadFile , @"C:\mypics\pic1.jpg");

WebRequestMethods.Ftp.UploadFile is a string whose value happens to be STOR so the compiler is assuming your are using the client.UploadFile(remoteName, localName) overload which is why your file is named STOR

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM