GregH
GregH

Reputation: 161

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");

Upvotes: 0

Views: 2384

Answers (2)

pabdulin
pabdulin

Reputation: 35225

@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.

Upvotes: 2

sgmoore
sgmoore

Reputation: 16077

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

Upvotes: 2

Related Questions