Salve, io avrei bisogno di inviare un file zip ad un server ftp con autenticazione.
Ho provato con il seguente codice preso dal sito msdn:
codice:
public static void Upload(string NomeFile, string Indirizzo, string User, string Password)
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(Indirizzo);
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential(User, Password);
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(NomeFile + ".zip");
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();
response.Close();
}
Mi da errore sulla riga Stream requestStream = request.GetRequestStream(); dicendomi URI richiesto non valido per questo comando FTP. Sinceramente non riesco a capire cosa voglia dire.
Grazie.