Link to home
Start Free TrialLog in
Avatar of Tek Info
Tek Info

asked on

Modify script to upload all CSV files found in a network share location to an FTP folder

I would like to change the following script so that it uploads all CSV files in the directory indicated to the FTP folder.

My goal is to have all CSV files found at \\VM1\FTP\Files uploaded to the remote FTP site inside folder /100

@ECHO OFF
ECHO Upload to FTP
ECHO Written by: Jason Faulkner
ECHO SysadminGeek.com
ECHO.
ECHO.

REM Usage:
REM UploadToFTP [/L] FileToUpload
REM
REM Required Parameters:
REM	FileToUpload
REM		The file or file containing the list of files to be uploaded.
REM
REM Optional Parameters:
REM	/L	When supplied, the FileToUpload is read as a list of files to be uploaded.
REM		A list of files should be a plain text file which has a single file on each line.
REM		Files listed in this file must specify the full path and be quoted where appropropriate.

SETLOCAL EnableExtensions

REM Connection information:
SET Server=
SET UserName=
SET Password=


REM ---- Do not modify anything below this line ----

SET Commands="%TEMP%\SendToFTP_commands.txt"

REM FTP user name and password. No spaces after either.
ECHO %UserName%> %Commands%
ECHO %Password%>> %Commands%

REM FTP transfer settings.
ECHO binary >> %Commands%

IF /I {%1}=={/L} (
	REM Add file(s) to the list to be FTP'ed.
	FOR /F "usebackq tokens=*" %%I IN ("%~dpnx2") DO ECHO put %%I >> %Commands%
) ELSE (
	ECHO put "%~dpnx1" >> %Commands%
)

REM Close the FTP connection.
ECHO close  >> %Commands%
ECHO bye    >> %Commands%

REM Perform the FTP.
FTP -d -i -s:%Commands% %Server%

ECHO.
ECHO.

REM Clean up.
IF EXIST %Commands% DEL %Commands%

ENDLOCAL

Open in new window

Avatar of Bill Prew
Bill Prew

Doesn't this solution to a prior question do that?  Just adjusting the local location.

@echo off
Title Multiple file Upload by Hackoo
mode con cols=85 lines=22 & Color A
::***********************************
Set FTPSERVER=sftp.sftp.com
Set USER=username
Set Password=password
Set LocalFolder=\\VM1\FTP\Files
Set RemoteFolder=/100
::***********************************
pushd %LocalFolder%
> ft.do echo Open %FTPSERVER%
>> ft.do echo %USER%
>> ft.do echo %Password%
>> ft.do echo prompt n
>> ft.do echo bin
>> ft.do echo cd %RemoteFolder%
>> ft.do echo mput *.csv
>> ft.do echo bye
ftp -s:ft.do
del ft.do
popd
Pause

Open in new window


»bp
@Tek Info,

Are you all set with this now, or do you need more help?  If all set, could you please close it out now.  If you need help with the question close process take a look at:



»bp
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.