Copy Code code as follows:
Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Net;
Using System.IO;
Namespace Ftponload
{
Class Program
{
static void Main (string[] args)
{
Ways to upload files
OnLoad ("D://output.txt");
Ways to download files
Fload ();
}
public static void onload (string file)
{
To construct a request object for a Web server
FtpWebRequest FTP;
Instantiating a File object
FileInfo f = new FileInfo (file);
FTP = (ftpwebrequest) ftpwebrequest.create (New Uri ("ftp://192.168.0.150/" + f.name));
Create User name and password
Ftp.credentials = new NetworkCredential ("123", "123");
Ftp.keepalive = false;
Ftp.method = WebRequestMethods.Ftp.UploadFile;
Ftp.usebinary = true;
Ftp.contentlength = F.length;
int bufflength = 20480;
byte[] buff = new Byte[bufflength];
int Contentlen;
Try
{
Gets the input stream of the request object
FileStream fs = F.openread ();
Stream SW = Ftp.getrequeststream ();
Contentlen = fs. Read (Buff, 0, bufflength);
while (Contentlen!= 0)
{
Sw. Write (Buff, 0, Contentlen);
Contentlen = fs. Read (Buff, 0, bufflength);
}
Sw. Close ();
Fs. Close ();
}
catch (Exception e)
{
Console.WriteLine (E.message);
}
}
public static void Fload ()
{
FtpWebRequest FTP;
FTP = (ftpwebrequest) ftpwebrequest.create (The New Uri ("ftp://192.168.0.6/connected to the file you specify");
Specify User name and password
Ftp.credentials = new NetworkCredential ("123", "123456");
WebResponse WR = Ftp.getresponse ();
StreamReader sr = new StreamReader (WR. GetResponseStream (), System.Text.Encoding.Default);
string s = Sr. ReadLine ();
while (S.equals (""))
{
s = Sr. ReadLine ();
}
}
}
}