VBA a přenos na/z FTP
Napsal: 27 kvě 2012 21:59
Ahoj,
měla bych otázku na přenos souborů na a z FTP pomocí VBA. Našla jsem x maker a 2 z nich zprovoznila, ale co mě trápí je to, že přenesený soubor (je jedno jakým směrem) se sice vytvoří ale byl nulové délky, takže nepoužitelný. A teď je tady otázka: co to způsobilo?
Mám WinXP SP3, Excel 2010 a FTP mám na ftp.sweb.cz (je to od seznam.cz)
A to makro je následující:
To druhé makro je hodně podobné, používá také ftp.exe obsažené ve win.
Budu vděčná za každou radu.
měla bych otázku na přenos souborů na a z FTP pomocí VBA. Našla jsem x maker a 2 z nich zprovoznila, ale co mě trápí je to, že přenesený soubor (je jedno jakým směrem) se sice vytvoří ale byl nulové délky, takže nepoužitelný. A teď je tady otázka: co to způsobilo?
Mám WinXP SP3, Excel 2010 a FTP mám na ftp.sweb.cz (je to od seznam.cz)
A to makro je následující:
Kód: Vybrat vše
Sub PublishFile()
Dim strDirectoryList As String
Dim lStr_Dir As String
Dim lInt_FreeFile01 As Integer
Dim lInt_FreeFile02 As Integer
On Error GoTo Err_Handler
lStr_Dir = ThisWorkbook.Path
lInt_FreeFile01 = FreeFile
lInt_FreeFile02 = FreeFile
'' ANW 07-Feb-2003 :
strDirectoryList = lStr_Dir & "\Prenos"
'' Delete completion file
If Dir(strDirectoryList & ".out") <> "" Then Kill (strDirectoryList & ".out")
'' Create text file with FTP commands
Open strDirectoryList & ".txt" For Output As #lInt_FreeFile01
Print #lInt_FreeFile01, "open ftp.sweb.cz"
Print #lInt_FreeFile01, "uživatel"
Print #lInt_FreeFile01, "heslo"
Print #lInt_FreeFile01, "cd /složka"
Print #lInt_FreeFile01, "binary"
Print #lInt_FreeFile01, "send " & ThisWorkbook.Path & "\pic.jpg /pic.jpg" 'pro odeslání
'Print #lInt_FreeFile01, "recv \pic.jpg " & ThisWorkbook.Path & "\pic.jpg" 'pro stažení
Print #lInt_FreeFile01, "bye"
Close #lInt_FreeFile01
'' Create Batch program
Open strDirectoryList & ".bat" For Output As #lInt_FreeFile02
Print #lInt_FreeFile02, "ftp -s:" & strDirectoryList & ".txt"
Print #lInt_FreeFile02, "Echo ""Complete"" > " & strDirectoryList & ".out"
Close #lInt_FreeFile02
'' Invoke Directory List generator
Shell (strDirectoryList & ".bat") ', vbHide '', vbMinimizedNoFocus
'Wait for completion
Do While Dir(strDirectoryList & ".out") = ""
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:03"))
'' Clean up files
If Dir(strDirectoryList & ".bat") <> "" Then Kill (strDirectoryList & ".bat")
If Dir(strDirectoryList & ".out") <> "" Then Kill (strDirectoryList & ".out")
If Dir(strDirectoryList & ".txt") <> "" Then Kill (strDirectoryList & ".txt")
bye:
Exit Sub
Err_Handler:
MsgBox "Error : " & Err.Number & vbCrLf & "Description : " & Err.Description, vbCritical
Resume bye
End Sub
To druhé makro je hodně podobné, používá také ftp.exe obsažené ve win.
Budu vděčná za každou radu.