FtpWebRequest returns error 550 File unavailable

前端 未结 15 2288
醉梦人生
醉梦人生 2020-11-30 09:41

I have created a small windows forms application to upload the file to one of our client\'s ftp site. But the problem that I\'m having is that when I run this application on

15条回答
  •  生来不讨喜
    2020-11-30 10:11

    Make sure target folder "outbox" exists. That was my problem with error 550.

    Simply create target directory "output" before upload.

    try
            {
                WebRequest request = WebRequest.Create("ftp://" + ftpServerIP + "/outbox");
                request.Credentials = new NetworkCredential("user", "password");
                request.Method = WebRequestMethods.Ftp.MakeDirectory;
                using (var resp = (FtpWebResponse)request.GetResponse())
                {
                    Console.WriteLine(resp.StatusCode);
                }
            }
            catch (WebException ex)
            {
                FtpWebResponse response = (FtpWebResponse)ex.Response;
                if (response.StatusCode == FtpStatusCode.ActionNotTakenFileUnavailable)
                {
                    response.Close();
                    //already exists
                }
                else
                {
                    response.Close();
                    //doesn't exists = it's another exception
                }
            }
    

提交回复
热议问题