무료Tools도구들

(추천)WinSCP free ftp 클라이언트 프로그램 + DOS bat 파일로 파일 업로드

saltdoll 2016. 8. 10. 06:39
반응형

WinSCP는 무료 FTP 프로그램입니다.

실질적으로 Putty나 Filezilla FTP를 이용한 연결정보 및 AWS의 ppk(보안키)를 가져 올 수 있는 기능도 있고 편리합니다.

심플하고, 무료임에 윈도우 환경에서 쓰기 좋은 FTP 프로그램 입니다.


경량의 WinSCP를 사용해 본 결과, FileZilla 보다는 Simple 하며 장점이 많은 프로그램입니다.

사이트별로 마지막에 접속한 위치(Remote path)와 경로(Local path)까지 기억을 하며,


개인적으로 WinSCP의 가장 장점이라고 생각하고 많이 사용하는 것은, 

cmd 환경의 Batch(.bat)파일 명령을 유용하게 사용하고 있습니다.





처음 알게 된것은 AWS에서 메뉴얼에서 나오는 프로그램이라 다운로드 받아 보았다. 


WinSCP Downloads:

http://winscp.net/eng/download.php



(참고) AWS 메뉴얼: 

https://docs.aws.amazon.com/ko_kr/AWSEC2/latest/UserGuide/putty.html?icmpid=docs_ec2_console




배치 파일에서 winscp로 ftp 파일 업로드


bat 파일에서 winscp을 이용해서 파일 업로드 


winscp는 PATH를 잡아주던가, 아니면 절대 경로로 써주면 됩니다.

아래는 파일을 접근해서 로그인후, 다운로드후 서버의 파일을 삭제하는 순서로 처리 되는 배치 파일 예제 입니다.


BAT 명령에 대한 설명

(1) dt라는 변수에 - 오늘의 "년도월일"형태의 값을 받습니다.

(2) Local PC에 e:드라이브로 이동하고, files라는 폴더까지 이동합니다.

(3) winscp로 ftp서버에 접속해서, BAK 디렉토리로 이동후, bak_년도월일.tra.gz파일을 로컬PC에 다운로드

(4) 서버의 bak_년도월일.tar.gz를 삭제

(5) ftp 종료로 bat파일 마무리




@ECHO OFF

for /f %%I in ('wmic os get localdatetime ^|find "20"') do set dt=%%I

set dt=%dt:~0,8%


E:

cd e:\backup\files\


winscp /command "open ftp://아이디:패스워드@FTP주소:포트" "bi" "cd BACK" "mget bak_%dt%.tar.gz" "rm bak_%dt%.tar.gz" "exit" 


 log 만들기 명령

winscp /log="e:\backup\files\logs\winscp_%dt%.log" /loglevel=0 /command "open ftp://아이디:패스워드@FTP주소:포트" "bi"  "mget bak_%dt%.tar.gz" "rm bak_%dt%.tar.gz" "exit"


참고로, 위의 작업은 ftp서비스를 통해서 Linux서버에 있는 root계정으로 사전에 cron작업으로 tar.gz은 생성한 백업 파일을 가져오는 형태 batch파일을  만들어 준내용입니다.

결론은, e:\bakcupback\files폴더에 bak_YYYYMMDD.tar.gz로 다운로드 받게됩니다.



CMD명령들 

winscp에서 파일 삭제 명령: https://winscp.net/eng/docs/scriptcommand_rm

winscp에서 스크립트 명령들: https://winscp.net/eng/docs/scripting#commands


winscp에서 command-line옵션: https://winscp.net/eng/docs/commandline




로그파일 만들기

(예제)

 winscp.exe sftp://martin@example.com/ /log="C:\winscp.log" /loglevel=0



(Sytax)

 winscp.com [/log=<logfile> [/loglevel=<level>] [/logsize=[count*]<size>]]
            [/xmllog=<logfile> [/xmlgroups]] [/nointeractiveinput]







Commands

The following commands are implemented.

To see help for the command, read respective documentation article below or type command help <command> directly in console.

CommandDescription
callExecutes arbitrary remote shell command
cdChanges remote working directory
checksumCalculates checksum of remote file
chmodChanges permissions of remote file
closeCloses session
cpDuplicates remote file
echoPrints message onto script output
exitCloses all sessions and terminates the program
getDownloads file from remote directory to local directory
helpDisplays help
keepuptodateContinuously reflects changes in local directory on remote one
lcdChanges local working directory
llsLists the contents of local directory
lnCreates remote symbolic link
lpwdPrints local working directory
lsLists the contents of remote directory
mkdirCreates remote directory
mvMoves or renames remote file
openConnects to server
optionSets or shows value of script options
putUploads file from local directory to remote directory
pwdPrints remote working directory
rmRemoves remote file
rmdirRemoves remote directory
sessionLists connected sessions or selects active session
statRetrieves attributes of remote file
synchronizeSynchronizes remote directory with local one



Parameters

Parameters for winscp.exe executable:

winscp.exe site|workspace|folder
winscp.exe <session_url>[/path/[file]]
winscp.exe [mysession] [/sessionname=<name>]
winscp.exe [mysession] [/newinstance]
winscp.exe [mysession] /edit <path>
winscp.exe [mysession] /synchronize [local_directory] [remote_directory] [/defaults]
winscp.exe [mysession] /keepuptodate [local_directory] [remote_directory] [/defaults]
winscp.exe [mysession] /refresh [path]
winscp.exe [mysession] /upload file1 file2 file3 ... [/defaults]
winscp.exe [mysession] [/privatekey=<file>] [/hostkey=<fingerprint>]
winscp.exe [mysession] [/clientcert=<file>] [/certificate=<fingerprint>]
winscp.exe [mysession] [/passive[=on|off]] [/implicit|explicit]
winscp.exe [mysession] [/timeout=<sec>]
winscp.exe [mysession] [/rawsettings setting1=value1 setting2=value2 ...]
winscp.exe [/console] [/script=script_file] [/command command1 command2 ...]
           [/parameter // param1 ...]
winscp.exe [/log=<logfile>  [/loglevel=<level>] [/logsize=[count*]<size>]]
           [/xmllog=<logfile> [/xmlgroups]]
winscp.exe [/ini=<inifile>]
winscp.exe [/rawconfig config1=value1 config2=value2 ...]
winscp.exe /batchsettings <site_mask> setting1=value1 setting2=value2 ...
winscp.exe /keygen keyfile [/output=output] [/changepassphrase] [/comment=comment]
winscp.exe /update
winscp.exe /help


반응형
도움이 되셨다면 하트모양의 "♡ 공감"을 눌러주시면 큰 격려가 됩니다.
(로그인하지 않으셔도 가능)