I have created a ftp server using Filezilla. I am trying to upload a single file using c# code. My cide is very simple a functino called upload:
static void UploadFile(string filepath)
{
string m_FtpHost = "http://ip:port/";
string m_FtpUsername = "userID";
string m_FtpPassword = "pass";
// Get an instance of WebClient
WebClient client = new System.Net.WebClient();
// parse the ftp host and file into a uri path for the upload
Uri uri = new Uri(m_FtpHost + new FileInfo(filepath).Name);
// set the username and password for the FTP server
client.Credentials = new System.Net.NetworkCredential(m_FtpUsername, m_FtpPassword);
// upload the file asynchronously, non-blocking.
client.UploadFileAsync(uri, "STOR", filepath);
}
static void Main(string[] args)
{
UploadFile("file.pdf");
Console.ReadKey();
}
In the Filezilla server gui I am getting the following messages:
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> STOR /file.pdf HTTP/1.1
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> 530 Please log in with USER and PASS first.
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> Content-Type: application/octet-stream
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> 500 Syntax error, command unrecognized.
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> Host: ip:port
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> 500 Syntax error, command unrecognized.
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> Content-Length: 481868
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> 500 Syntax error, command unrecognized.
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> Expect: 100-continue
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> 500 Syntax error, command unrecognized.
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> Connection: Keep-Alive
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> 500 Syntax error, command unrecognized.
(000017)11/23/2015 10:47:19 AM - (not logged in) (ip)> disconnected.
Any idea what might be wrong here? EDIT: I tried to change http with ftp in the UploadFile. Now I am receiving the following:
(000019)11/23/2015 10:59:53 AM - chrathan user (ip)> 257 "/" is current directory.
(000019)11/23/2015 10:59:53 AM - user (ip)> TYPE I
(000019)11/23/2015 10:59:53 AM - user (ip)> 200 Type set to I
(000019)11/23/2015 10:59:53 AM - user (ip)> PASV
(000019)11/23/2015 10:59:53 AM - user (ip)> 227 Entering Passive Mode (ip with comma)
(000019)11/23/2015 10:59:53 AM - user (ip)> STOR file.pdf
(000019)11/23/2015 10:59:53 AM - user (ip)> 150 Opening data channel for file upload to server of "/file.pdf"
(000019)11/23/2015 10:59:53 AM - user (ip)> 550 can't access file.
(000019)11/23/2015 10:59:53 AM - user (ip)> disconnected.
EDIT2: Basically the folder I try to have access is a network share disk. When I changed to a local folder in my pc everything works. My issue finally is how can I have access to a network share disk?
Your m_FtpHost
variable is set to use http, it needs to be ftp://ip:port/
.
Thats why the first line of your log is showing: STOR /file.pdf HTTP/1.1