‫  ا

ا  ا‬
‫ا م  ور  ا
و آ ‬

‫آ  ﻡ ‪Vb.net ! FTP‬‬
‫آ‪ $‬ا‪#‬رس ‪:‬ا ‪ #‬زآی ﺹ‪(ahmed z s)%‬‬
‫ا ‪ahmedzs@live.ca :‬‬
‫ﻡ ه‪ +‬ا*ف  ‬

‫)را ‪ 1‬ی‪0‬ح ﻡ ه‪ +‬ال ‪ FTP‬ﻡ وی‪#3‬ی ا‪( 2‬‬

‫اف   ه    ات ا دة 
  )‪(FTP Server‬‬

‫!ة  ‪ 5‬ا‪3‬ﻡ‬
‫ا*ة ه ا  

') ا اف  
 و(  '&‪ %‬و‪ #‬ذ‬

د ‪  +‬اف  
  
‪ (0‬و‪ /‬ات ا '&‪ /‬او ی‪%&'  ,-‬‬

‫‪1‬‬

‫ح‬0‫ﻡ ﻡ ا‬3‫اد ﺹ ا‬+‫اآ‬
System.Net.WebRequest.Create - System.Net.FtpWebRequest
#‫ی‬#@ ‫ء ﻡ‬0* ‫ او =<ف او‬5 => ?‫ ﻡ‬2‫ ﻡ ﻡ ﻡ‬5‫ﻡ‬2> (  ‫; ال اف‬+‫ ا ا !)ﻡ‬$8 ‫ﺹ رﺱل‬:
‫د‬+ *‫ ا‬# 5?‫ﻡ‬
‫اس‬:

Dim clsRequest As System.Net.FtpWebRequest =
(System.Net.WebRequest.Create("ftp://" & " 2‫ ﻡ‬5‫ﻡ‬2>‫ ا‬#‫))"ﻡن ا  ا<ي ی‬

clsRequest.Credentials - System.Net.NetworkCredential
(‫رد‬+‫ﺱ‬3‫م وا‬#H> ‫ )اﺱ ا‬G ‫ص‬H‫ت ﺱ! ا*ف  ا‬3 ‫ص‬: 32>‫ ا‬E<‫ه‬
‫اس‬:

clsRequest.Credentials = NewSystem.Net.NetworkCredential(‘User
Name, Password)
clsRequest.Method - System.Net.WebRequestMethods.Ftp
>!*‫ ا ﺱ! ا‬38 #‫ي ا*ﻡ ا<ي ی‬+>=>‫ ه ا> ﺱ‬I‫ ا‬J ‫ا ه اه دا‬#‫ ا‬E<‫ه‬
:I E‫د‬+@+‫وا*ت ا> ﻡ‬#‫واه ا‬
DeleteFile ‫=<ف ﻡ‬
DownloadFile‫ ﻡ‬5 =>
ListDirectory E‫د‬+@+ ‫ات ا‬#L ‫ت وا‬M   N; 5 2
UploadFile‫! ﻡ‬
RemoveDirectory 2‫ ﻡ‬#L‫=<ف ﻡ‬
MakeDirectory #‫ی‬#@ #L‫ ﻡ‬

clsRequest.Method = System.Net.WebRequestMethods.Ftp.DeleteFile 
* $O‫ﻡ ارﺱ ا‬# ‫د‬# ‫ <ف ا  ا<ي‬38 ‫<ا ا*ﻡ‬I ‫و‬ 
38 ‫<( ﻡ‬M) ‫  ا‬L>‫ ﻡ ا*ف  ﺱ! ا*ﺱ‬$O G‫ ذ‬#2

Dim ftpWebResp As FtpWebResponse = clsRequest.GetResponse() 

‫( ﻡ‬System.Net.WebRequestMethods.Ftp)‫د‬+? ‫ ا‬Q! ?‫ ﻡ‬#L‫!ذا اردت ان =<ف ﻡ‬
Create ‫رس ﻡ‬#‫د ! اول ا‬# ‫ ا<ي‬#L ‫ ﻡ ر ا‬Q ‫ ﻡ‬RemoveDirectory ‫ ا‬DeleteFile

DeleteFile 1 ‫ف‬,2
RemoveDirectory 3  #0 ‫ف‬,2
MakeDirectory #‫ی‬#@ #L‫ ﻡ‬

5?‫ ﻡ‬R‫  ا ! ﺵ‬5‫ ان یﺱ‬#‫ ﻡ ا ! و* ی‬R‫ ﺵ‬38 ‫ ا‬J  ‫ ﻡ <ف ا‬I>‫ ا‬#; ‫ا ا*ن‬
Upload ‫ت‬M ‫ ر! ا‬# R‫  ! ﺵ‬5‫ او ﺱ‬Download ‫ ﻡ‬5 = #
#L‫ او ﺹ ﻡ‬#L‫ ﻡ او ﻡ‬% ‫ ﻡ‬$8 # M U‫ی‬O‫ ا‬E<‫ ه‬. >‫رس ا‬#‫ ! ا‬5M> ‫ح ه<ا‬0‫وﺱ‬
#‫ی‬#@

2

:‫ت‬M ‫ ا‬5 = ‫ر! و‬
UploadFile ‫ا‬#‫ت ا‬M ‫ر! ا‬
‫ ﻡ او ر! ﻡ او رص‬5 = $8  !  L>  ! ‫ ا ﺱ! ا*ف  ﺱد ه<ا ا‬$O‫ ان ارﺱ ا‬#2
‫ت‬M ‫ات و ا‬#L ‫ا‬ 
*  L> ‫ ا‬$8 ‫د‬+‫ ا<ي * ﻡ @<ف آ‬$O‫د ا‬+‫ ا‬#2 ‫د‬+‫ ه<ا ا‬$> UploadFile ‫ا‬# ‫ ر! ﻡ‬$8 #
<M> ! ‫ﻡ ا‬W ‫د او‬+‫و‬#‫د ا‬+‫ آ‬5?‫  ! ت( )و* =>ج اي ت ﻡ ا ! ﻡ‬5‫ﺱ! ﻡ )اي ا ﺱﺱ‬
! 2‫ ارﺱل ت ﻡ ﻡ‬5?‫  ﻡ ا ! ﻡ‬L>‫ ا*ﺱ‬$8) ! ‫م‬#H> ‫  ی‬L>‫د ا*ﺱ‬+‫ت )آ‬M ‫ ا‬% ‫د ﻡ‬+‫ آ‬5?‫ ﻡ‬2‫ ﻡ‬R‫ﺵ‬
(‫ت‬M ‫ ا‬% ‫د ﻡ‬+‫ آ‬5?‫ ا ! ﻡ‬5:‫ دا‬2‫ ﻡ‬R‫< ﺵ‬M) ‫ن( او‬+ X‫ا ! ا ا‬
‫اس‬:

Dim Streamer As System.IO.Stream = clsRequest.GetRequestStream()
Dim bFile() As Byte = System.IO.File.ReadAllBytes(" ! 5‫ی‬X>‫ ا‬#‫ا  ا<ي ی‬ 
‫ﻡ ا*ﺱ‬
5‫ی‬X>‫ ا‬#‫)"ا<ي ی‬
Streamer.Write(bFile, 0, bFile.Length
Streamer.Close()
Streamer.Dispose()

DownloadFile ‫ا‬#‫ت ا‬M ‫ ا‬5 = 
‫ا‬#‫ ا‬E<‫ ا<ي * )! ه‬$O‫د ا‬+‫ ا‬#2 ‫د‬+‫ ه<ا ا‬$> ‫ و‬DownloadFile ‫ا‬#‫م ا‬#H>  ‫ ﻡ‬5‫ی‬X $8 #
(! ‫ت ﻡ ا‬3‫=>ج ا‬
‫اس‬:

Dim streamer As Stream = ftpWebResp.GetResponseStream()
Using fs As New IO.FileStream(" ‫ ا‬5‫ی‬X ‫ﻡن‬C:\file.txt", FileMode.Create)
Dim buffer(2047) As Byte
Dim read As Integer = 0
(Bytes)‫ت‬3‫ ا‬5‫ آ‬5‫ی‬X ‫  و‬L >‫ > ی‬Loop 5 2‫ ی‬5Y‫د ا> ﺱ‬+‫ا‬
‫اس‬:

Do
read = streamer.Read(buffer, 0, buffer.Length)
fs.Write(buffer, 0, read)
Loop Until read = 0
fs.Flush()
fs.Close()
streamer.Close()
End Using

3

‫ او‬ListDirectory ‫ا‬#‫دة ا‬+@+ ‫ات ا‬#L ‫ت و ا‬M   N; 5 
ListDirectoryDetails
#2 ‫د‬+‫ ه<ا ا‬$>‫ و‬ListDirectory ‫ا‬#‫م ا‬#H>  ! ‫دة ! ا‬+@+ ‫ات ا‬#L ‫ت وا‬M   N;  L $8 #
(‫د‬+‫و‬#‫ ا‬5?‫ت ﻡ ا ! ﻡ‬3‫ا =>ج ا‬#‫ ا‬E<‫د ا<ي * )! ه‬+‫ا‬
Dim ftpWebResp As FtpWebResponse = clsRequest.GetResponse()
Dim streamer As Stream = ftpWebResp.GetResponseStream()
Dim reader As New StreamReader(streamer)
Dim LineRead As String
Listview1 ! ‫ات‬#L ‫ت وا‬M ‫ ا‬5‫  آ‬L >‫ > ی‬loop 5 2‫ ی‬5Y‫د ا> ﺱ‬+‫ا‬
‫اس‬:

Do Until reader.EndOfStream
LineRead = reader.ReadLine
ListView1.Items.Add(LineRead)
Loop
streamer.Close()

(5I‫ وﺱ‬1 ) FTP ‫ﻡ‬3 2‫ه<ا ﻡ?ل ﻡ ﺹ‬
http://www.mediafire.com/download.php?joinlt3yozi

‫ ا‬# =  
N‫ د‬%‫ ﻡ ﺹ‬+  * 
=

4

Sign up to vote on this title
UsefulNot useful