Các bạn giúp mình vụ này với,
Mình muốn copy 1 file từ thư mục trên máy cá nhân lên FTP server dùng lệnh của VB6.0. (Bản thân máy tính đã kết nối thành công với ftp).
Cụ thể như sau: muốn copy một file: abc.txt từ thư mục D:\abc.txt lên ftp://193.163.248.24/abc/
Mình dùng Visual Basic 6.0.
// Mình có dùng cái này nhưng không được.
Dim f As New FileSystemObject, ff
Set ff = f.GetFile("D:\abc.txt")
ff.Copy ("ftp://193.163.248.24/abc/")
Cảm ơn rất nhiều,
- Vui lòng đọc nội qui diễn đàn để tránh bị xóa bài viết
- Tìm kiếm trước khi đặt câu hỏi
Copy file từ máy tính sang FTP
Re: Copy file từ máy tính sang FTP
Mình sử dụng thư viện để thực hiện đồng bộ
Trước tiên bạn import thư viện
Sau đó sử dụng thủ tục này để giải quyết
[vbnet] Dim ftp As New FTPclient("" & txtDiaChi.Text & "", "" & txtUserName.Text & "", "" & txtpassword.Text & "")
labelTientrinh.Text = "Kết nối thành công"
System.Threading.Thread.Sleep(1000)
ProgressBarX1.Value = 50
labelTientrinh.Text = "Đang sao lưu cơ sở dữ liệu lên máy chủ, có thể mất vài phút"
'download a file (permitting overwrite)
If ftp.FtpFileExists("/" & Now.Day & "" & Now.Month & "" & Now.Year & ".mdb") Then
'rename a file
ftp.FtpRename("/" & Now.Day & "" & Now.Month & "" & Now.Year & ".mdb", "" & Now.Day & "" & Now.Month & "" & Now.Year & "old.mdb")
End If
ftp.Upload("" & Application.StartupPath & "\database.mdb", "/" & Now.Day & "" & Now.Month & "" & Now.Year & ".mdb")
ProgressBarX1.Value = 100
labelTientrinh.Text = "Sao lưu thành công!"[/vbnet]
Lấy list file trong thư mục
[vbnet]Sub get_ComboBox()
Try
Dim ftp As New FTPclient("" & txtDiaChi.Text & "", "" & txtUserName.Text & "", "" & txtpassword.Text & "")
Dim result As List(Of String) = ftp.ListDirectory("/")
cbmaphuchoi.Enabled = True
cbmaphuchoi.DataSource = result
Catch ex As Exception
labelTientrinh.Text = "Hiện không có kết nối !"
End Try
End Sub[/vbnet]
Trước tiên bạn import thư viện
Sau đó sử dụng thủ tục này để giải quyết
[vbnet] Dim ftp As New FTPclient("" & txtDiaChi.Text & "", "" & txtUserName.Text & "", "" & txtpassword.Text & "")
labelTientrinh.Text = "Kết nối thành công"
System.Threading.Thread.Sleep(1000)
ProgressBarX1.Value = 50
labelTientrinh.Text = "Đang sao lưu cơ sở dữ liệu lên máy chủ, có thể mất vài phút"
'download a file (permitting overwrite)
If ftp.FtpFileExists("/" & Now.Day & "" & Now.Month & "" & Now.Year & ".mdb") Then
'rename a file
ftp.FtpRename("/" & Now.Day & "" & Now.Month & "" & Now.Year & ".mdb", "" & Now.Day & "" & Now.Month & "" & Now.Year & "old.mdb")
End If
ftp.Upload("" & Application.StartupPath & "\database.mdb", "/" & Now.Day & "" & Now.Month & "" & Now.Year & ".mdb")
ProgressBarX1.Value = 100
labelTientrinh.Text = "Sao lưu thành công!"[/vbnet]
Lấy list file trong thư mục
[vbnet]Sub get_ComboBox()
Try
Dim ftp As New FTPclient("" & txtDiaChi.Text & "", "" & txtUserName.Text & "", "" & txtpassword.Text & "")
Dim result As List(Of String) = ftp.ListDirectory("/")
cbmaphuchoi.Enabled = True
cbmaphuchoi.DataSource = result
Catch ex As Exception
labelTientrinh.Text = "Hiện không có kết nối !"
End Try
End Sub[/vbnet]
- Attachments
-
- FTPclient.zip
- (8.98 KiB) Downloaded 471 times
Return to “[VB] Module, Class, UserControl, OCX”
Who is online
Users browsing this forum: No registered users and 0 guests