C winfrom 模擬ftp檔案管理

2022-08-05 03:30:20 字數 2900 閱讀 3342

從網上找到的非常好用的模擬ftp管理**,整理了一下,希望對需要的人有幫助

using system; 

using system.collections.generic;

using system.text;

using system.net;

using system.io;

using system.windows.forms;

namespace convertdata

public ftpupdown(string ftpserverip, string ftpuserid, string ftppassword)

//都呼叫這個

private string getfilelist(string path, string wrmethods)//上面的**示例了如何從ftp伺服器上獲得檔案列表

// to remove the trailing '\n'

result.remove(result.tostring().lastindexof('\n'), 1);

reader.close();

response.close();

return result.tostring().split('\n');

}catch (exception ex)

}public string getfilelist(string path)//上面的**示例了如何從ftp伺服器上獲得檔案列表

public string getfilelist()//上面的**示例了如何從ftp伺服器上獲得檔案列表

public void upload(string filename) //上面的**實現了從ftp伺服器上載檔案的功能

// 關閉兩個流

strm.close();

fs.close();

}catch (exception ex)

}string url = "ftp://" + ftpserverip + "/" + filename;

connect(url);//連線

reqftp.credentials = new networkcredential(ftpuserid, ftppassword);

ftpwebresponse response = (ftpwebresponse)reqftp.getresponse();

stream ftpstream = response.getresponsestream();

long cl = response.contentlength;

int buffersize = 2048;

int readcount;

byte buffer = new byte[buffersize];

readcount = ftpstream.read(buffer, 0, buffersize);

filestream outputstream = new filestream(newfilename, filemode.create);

while (readcount > 0)

ftpstream.close();

outputstream.close();

response.close();

errorinfo = "";

return true;

}catch (exception ex)

}//刪除檔案

public void deletefilename(string filename)

catch (exception ex)

}//建立目錄

public void makedir(string dirname)

catch (exception ex)

} //刪除目錄

public void deldir(string dirname)

catch (exception ex)

}//獲得檔案大小

public long getfilesize(string filename)

catch (exception ex)

return filesize;

}//檔案改名

public void rename(string currentfilename, string newfilename)

catch (exception ex)

}//獲得檔案明晰

public string getfilesdetaillist()

//獲得檔案明晰

public string getfilesdetaillist(string path)

}}

上面為類,舉例證明如何代用

private void button1_click(object sender, eventargs e)//檔案上傳

private void button3_click(object sender, eventargs e)//修改

private void button4_click(object sender, eventargs e)//刪除

private void button2_click(object sender, eventargs e)//新增

//獲得ftp檔案的檔案明晰,還為處理,能夠獲得所有的檔名稱

ftpupdown ftpupdown = new ftpupdown("192.168.2.130", "wl", "123456");

string str = ftpupdown.getfilesdetaillist();

int i = 1;

foreach (string item in str)

label1.text = i.tostring();

python socket 模擬 FTP處理檔案

解析 的思路 首先,先將伺服器和客戶端的建立連線,連線成功後,客戶端要先將自己的請求傳送至server,因為ftp的get是處理檔案的,所以採用cmd.startwith get 作為判斷條件,這個時候必須收到server的應答,server response,表示server已經準備可以接受資料了...

ftp傳送檔案

ftp ftp open 10.173.255.58 connected to 10.173.255.58 10.173.255.58 220 vsftpd 2.2.2 name 10.173.255.58 gbase 331 please specify the password.password...

FTP檔案處理

org.apache.commons.net.ftp.ftpclientapache的ftpclient包有許多方便的函式操作 在使用時候需要注意 中文名稱檔案編碼 ftp檔案中文名稱的編碼是 iso 8859 1 new string filename.getbytes gbk iso 8859 ...