Witam
Mam problem z wysłaniem pliku z dysku na serwer ftp korzystam z kodu zamieszczonego na stronie msdn.microsoft.com jednak efektem jest błąd.
Kod:
public void test()
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(@"ftp://ftp.adres.cba.pl/test.txt");
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("nazwa_uzytkownika", "haslo");
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(@"E:\test.txt");
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
MessageBox.Show(response.StatusDescription, "info", MessageBoxButtons.OK);
response.Close();
}
Przy linijce:
Stream requestStream = request.GetRequestStream();
jest zgłaszany błąd (podczas próby wykonania):
WebException was unhandled
An unhandled exception of type 'System.Net.WebException' occurred in System.dll
Additional information: Serwer zdalny zwrócił błąd: (553) Nazwa pliku niedozwolona.
Ktoś może wie gdzie leży błąd w nazwie? Może jakiegoś "/" lub "" trzeba gdzieś wstawić. Przy pomocy programu do wysyłania pliku na serwer bez kłopotu da się wskazany plik na serwerze skopiować.