sitelink1 | https://blog.edit.kr/entry/WinSCP-free-f...8%EB%9E%A8 |
---|---|
sitelink2 | http://winscp.net/eng/download.php |
sitelink3 | |
extra_vars6 |
Putty나 Filezilla FTP를 이용한 연결정보 및 ppk를 가져 올 수 있는 기능이 있음
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를 잡아주던가, 아니면 절대 경로로 써주면 됩니다.
아래는 파일을 접근해서 로그인후, 다운로드후 서버의 파일을 삭제하는 순서로 처리 되는 배치 파일 예제 입니다.
@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\
REM 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"
winscp /command "open ftp://아이디:패스워드@FTP주소:포트" "bi" "cd BACK" "mget bak_%dt%.tar.gz" "rm bak_%dt%.tar.gz" "exit" |
(참고로, 사전에 tar.gz은 서버에서 압축을 root계정에서 cron으로 생성한걸 만들어 준다.)
결론은, e:\bakcupback\files폴더에 bak_YYYYMMDD.tar.gz로 다운로드 받게됩니다.
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>]] |
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.
Command | Description |
---|---|
call | Executes arbitrary remote shell command |
cd | Changes remote working directory |
checksum | Calculates checksum of remote file |
chmod | Changes permissions of remote file |
close | Closes session |
cp | Duplicates remote file |
echo | Prints message onto script output |
exit | Closes all sessions and terminates the program |
get | Downloads file from remote directory to local directory |
help | Displays help |
keepuptodate | Continuously reflects changes in local directory on remote one |
lcd | Changes local working directory |
lls | Lists the contents of local directory |
ln | Creates remote symbolic link |
lpwd | Prints local working directory |
ls | Lists the contents of remote directory |
mkdir | Creates remote directory |
mv | Moves or renames remote file |
open | Connects to server |
option | Sets or shows value of script options |
put | Uploads file from local directory to remote directory |
pwd | Prints remote working directory |
rm | Removes remote file |
rmdir | Removes remote directory |
session | Lists connected sessions or selects active session |
stat | Retrieves attributes of remote file |
synchronize | Synchronizes 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