1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| public void upload()
{
ModifyRegistry myRegistry = new ModifyRegistry();
myRegistry.SubKey = "SOFTWARE\\JJJJJJJJJ\\VIDEO";
myRegistry.ShowError = true;
string path = myRegistry.Read("path");
string FTPAddress = "ftp://JJJJJJ@JJJJJJ.ca";
string filePath = path + fileName;
string username = "usage.1";
string password = "123456";
try
{
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTPAddress + "//www//fffffff.com//library//" + Path.GetFileName(filePath));
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential(username, password);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
//Load the file
FileStream stream = File.OpenRead(filePath);
byte[] buffer = new byte[stream.Length];
stream.Read(buffer, 0, buffer.Length);
stream.Close();
//Upload file
Stream reqStream = request.GetRequestStream();
reqStream.Write(buffer, 0, buffer.Length);
reqStream.Close();
// delete File on hard disk
DeleteFile(filePath);
}
catch (Exception ex)
{
MessageBox.Show("Unable to upload file\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
} |
Partager