Ho un file .bat di base che si collega a un server FTP, salva l'elenco di file CSV e quindi scarica tutti i file CSV dal server FTP. Sto usando VBA per chiamare la shell per eseguire il file .bat. Sul mio computer portatile del lavoro (Windows 10) tutto funziona bene, ma se lo faccio funzionare su Windows Server 2012 R2, il file .bat si blocca perché il server FTP sta dando l'errore:Comportamento FTP insolito durante la chiamata di file batch da VBA su Windows Server 2012 R2
425 Can't open data connection for transfer of "/*.csv
sto usando un PC con il server FileZilla con cui testare e ho anche accesso al server FTP del mio client (non sono sicuro di quello che stanno eseguendo).
Questo è quello che ho provato:
Su Windows 10 e Windows Server 2012 R2 - Firewall sistemi operativi disabili, a 64 bit, Excel 2010 a 32 bit.
In Windows 10 computer portatile:
- esecuzione di file batch dal prompt dei comandi funziona bene
- esecuzione la stringa di comando dalla finestra Esegui di Windows (Winkey + R) che il mio codice VBA sta usando, opere bene
- eseguendo il file batch come un compito tramite l'Utilità di pianificazione, funziona bene
- esecuzione del sub VBA che chiama la shell per eseguire il file .bat, funziona bene
In Windows Server 2012 R2:
- esecuzione di file batch dal prompt dei comandi funziona bene
- esecuzione la stringa di comando dalla finestra Esegui di Windows (Winkey + R) che il mio codice VBA sta usando , funziona bene
- eseguendo il file batch come un compito tramite l'Utilità di pianificazione, funziona bene
il problema:
- Eseguendo il sub VBA che chiama la shell per eseguire il file .bat, batch viene interrotto. Guardando il server FTP, il file batch completa il log in, e poi mostra l'errore 425:
(000046)9/21/2015 10:36:11 AM - test (10.32.0.75)> 150 Opening data channel for directory listing of "/.csv"
(000046)9/21/2015 10:36:22 AM - test (10.32.0.75)> 425 Can't open data connection for transfer of "/.csv"
(000046)9/21/2015 10:36:26 AM - test (10.32.0.75)> disconnected.
Mi sembra di fare questo quando provo eseguire il file batch utilizzando VBA sulla macchina server 2012 R2 . Sono in perdita ... qualche idea?
Batch codice del file:
@echo off
REM Enter the username
echo user test> ftpcmd.dat
REM Enter the password
echo test>> ftpcmd.dat
REM Change the local computers' directory
echo lcd D:/XLRX/FTP/FTP_Tickets>> ftpcmd.dat
REM Get a list of the csv files we're about to copy
echo ls *.csv D:/XLRX/FTP/TESTCopiedCSV.txt>> ftpcmd.dat
REM Download all the csv files to the local directory
echo mget *.csv>> ftpcmd.dat
REM Remove the files we just downloaded from the FTP server
REM Close the connection
echo quit >> ftpcmd.dat
REM use -d for debugging, -i for preventing user interaction questions
ftp -i -n -s:ftpcmd.dat xxx.xxx.xxx.xxx
REM Clean Up
del ftpcmd.dat
REM Close the command window
EXIT
codice VBA:
'Call the batch file to pull down the FTP tickets to the local server
sToday = Format(Now, "yyyymmdd_hhmm")
''-----------------------------------TEST CODE--------------------------------------''
''The following line works from the Windows RUN prompt on the EnerVest server:
''cmd /k "cd /d d:\xlrx\FTP && TESTGetFTPTickets.bat" >> D:\XLRX\FTP\FTP_Logs\TEST.log
If sTesting = "NO" Then
sFTPLogName = sToday & ".log" 'Sets the FTP log filename
sCMD = "cmd /k " & """cd /d D:\xlrx\FTP && GetFTPTickets.bat"""
Else
sFTPLogName = "TEST_" & sToday & ".log" 'Sets the FTP log filename if testing
sCMD = "cmd /k " & """cd /d D:\xlrx\FTP && TESTGetFTPTickets.bat"""
End If
sLog = ">> " & sFTPLogFolder & "\" & sFTPLogName
vArguments = Array(sCMD, sLog) 'New Code 9/20/2015
sShell = Join(vArguments, " ") 'Joins the above arguments into a string separated by " " (spaces)
'Call the Shell (command line) and use the sShell
Call Shell(sShell)
Non hai mai impostato 'sFTPLogFolder' nel codice VBA ... – aschipfl
È possibile abilitare i trasferimenti passivi sul client FTP di Server 2012? Questo fa la differenza? – rojo
sFTPLogFolder è impostato in precedenza nel codice; tuttavia non ha alcun effetto sull'errore del server FTP. –