주요 콘텐츠로 건너뛰기
많은 사람들이 FTP를 사용하여 파일을 전송하기 위해 자동화 된 프로세스를 만들었습니다. 이 작업을 수행하는 몇 가지 방법이 있습니다, 다른 사람보다 더 나은 몇 가지. 이 블로그는 다양한 접근 방식을 논의하고 각각의 장점과 단점을 식별합니다. 또한 불완전한 파일이 전송될 수 있는 문제도 다룹니다.
가장 간단한 방법은 사용자 ID, 암호 및 모든 FTP 요청을 명령 매크로(그림 1)에 넣고 실행하기만 하면 됩니다(그림 2).
&attach_input
ftp 172.16.1.116
Noah_Davids
MYPASSWORD
put foo
&if (command_status) ^= 226 &then &goto ERROR1
get bar
&if (command_status) ^= 226 &then &goto ERROR2
quit
&
&label ERROR1
..display_line Could not put file
quit
&return
&
&label ERROR2
..display_line Could not get file
quit
&return

그림 1 – ftp1.cm - 간단한 명령 매크로
ftp1
Connected to 172.16.1.116.
220 phx_vos-m16 FTP server (FTP 1.0 for Stratus STCP) ready. (Compatible with OS
+ TCP/IP)
User (172.16.1.116:Noah_Davids): 331 Password required for nd.
Password:
230 User Noah_Davids.CAC logged in.
200 PORT command successful.
150 Opening data connection for foo (172.16.1.34,49253)0.
226 Transfer complete.
80 bytes sent in 0.01 seconds (6.85 Kbytes/sec)
200 PORT command successful.
550 bar: No such file or directory.
recvrequest: Bad file number.
Get transfer did not complete
Could not get file
221 Goodbye.
그림 2 – ftp1.cm - 간단한 명령 매크로 실행
이 방법의 무승부는 사용자 ID와 더 중요한 것은 암호가 매크로의 일부로 명확한 텍스트에 있다는 것입니다. 매크로에 액세스할 수 있는 사람은 누구나 볼 수 있습니다. 두 번째 방법은 .netrc 파일을 사용하여 사용자 ID와 암호를 유지하는 것입니다. (그림 3). 명령 매크로(그림 4)에는 실행하기 위한 FTP 요청만 포함됩니다(그림 5).
machine 172.16.1.116
login Noah_Davids
password MYPASSWORD
그림 3 – .netrc 파일
&attach_input
ftp 172.16.1.116
put foo
&if (command_status) ^= 226 &then &goto ERROR1
get bar
&if (command_status) ^= 226 &then &goto ERROR2
quit
&
&label ERROR1
..display_line Could not put file
quit
&return
&
&label ERROR2
..display_line Could not get file
quit
&return
그림 4 – ftp2.cm - 사용자 ID 및 암호없이 매크로를 명령
ftp2
Connected to 172.16.1.116.
220 phx_vos-m16 FTP server (FTP 1.0 for Stratus STCP) ready. (Compatible with OS
+ TCP/IP)
331 Password required for nd.
230 User Noah_Davids.CAC logged in.
200 PORT command successful.
150 Opening data connection for foo (172.16.1.34,49256)0.
226 Transfer complete.
80 bytes sent in 0.04 seconds (2.09 Kbytes/sec)
200 PORT command successful.
550 bar: No such file or directory.
recvrequest: Bad file number.
Get transfer did not complete
Could not get file
221 Goodbye.
그림 5 – ftp2.cm - 사용자 ID 및 암호없이 명령 매크로 실행
.netrc 파일은 소유자가 파일에 액세스할 수 있는 유일한 파일(그림 6)인 경우에만 작동합니다. 다른 사람이 읽기 액세스(그림 7)가 작동하지 않고 암호 프롬프트가 표시됩니다(그림 8).
display_access .netrc -all
%phx_vos#m15_mas>SysAdmin>Noah_Davids>.netrc
w  Noah_Davids.*
n  *.*
그림 6 – .netrc 파일에 대한 올바른 ACL
display_access .netrc -all
%phx_vos#m15_mas>SysAdmin>Noah_Davids>.netrc
w  Noah_Davids.*
r  *.CAC
n  *.*
그림 7 – .netrc 파일에 잘못된 ACL
ftp2
Connected to 172.16.1.116.
220 phx_vos-m16 FTP server (FTP 1.0 for Stratus STCP) ready. (Compatible with OS
+ TCP/IP)
User (172.16.1.116:Noah_Davids): 331 Password required for put foo.
Password:
530 Login incorrect.
Login failed.
221 Goodbye.
그림 8 – .netrc가 잘못된 ACL이있을 때 암호 프롬프트
FTP 매크로를 만들어 .netrc 파일에 모든 명령을 배치할 수 있습니다. 매크로가 "init"(그림 9)이라는 경우 로그인 후 자동으로 실행되며 VOS 명령 매크로가 1줄(그림 10) FTp 명령으로 만듭니다. 이 방법의 주요 문제는 오류 복구가 없다는 것입니다. (command_status) 함수(그림 11)를 사용하여 FTP 요청의 상태를 확인할 수 없습니다.
machine 172.16.1.116
login Noah_Davids
password MYPASSWORD
macdef init
put foo
get bar
quit
그림 9 – 이니트 매크로가 있는 .netrc 파일
ftp 172.16.1.116
그림 10 – ftp3.cm – 인it FTP 매크로가 포함된 .netrc 파일과 함께 사용할 때 매크로
ftp3
Connected to 172.16.1.116.
220 phx_vos-m16 FTP server (FTP 1.0 for Stratus STCP) ready. (Compatible with OS
+ TCP/IP)
331 Password required for nd.
230 User Noah_Davids.CAC logged in.
put foo
200 PORT command successful.
150 Opening data connection for foo (172.16.1.34,49276)0.
226 Transfer complete.
80 bytes sent in 0.01 seconds (9.52 Kbytes/sec)
get bar
200 PORT command successful.
550 bar: No such file or directory.
recvrequest: Bad file number.
Get transfer did not complete
quit
221 Goodbye.
그림 11 – ftp3.cm – 매크로 사용 시 출력 - 오류 복구 없음
매크로가 FTP를 사용하여 전송할 때 파일이 디렉터리에 표시되기를 기다리는 루프를 보었던 많은 매크로(그림 12).
&attach_input
&label AGAIN
&if (exists new_file) = 1 &then &goto FTP
display_line No new_file as of (time)
sleep -seconds 15
&goto AGAIN
&
&
&label FTP
ftp 172.16.1.116
put new_file
&if (command_status) = 226 &then ..display_line OK
&else &do
..display_line
..display_line ERROR
..display_line
&end
quit
그림 12 – ftp4.cm - 매크로가 파일이 나타나고 전송되기를 기다리고 있습니다.
이 방법의 문제는 FTP가 여전히 열려 있고 작성중인 파일을 읽을 수 있다는 것입니다. 큰 파일의 경우 또는 타이밍이 좋지 않은 경우 결과는 파일의 일부만 전송됩니다(그림 13).
1234567890
abcdefghij
1234567890
abcdefghij
1234567890
abcdefghij
1234567890
abcdefghij
1234567890
abcdefghij
그림 13 – 파일의 일부만 전송됩니다.
1234567890
abcdefghij
1234567890
abcdefghij
1234567890
abcdefghij
1234567890
abcdefghij
1234567890
abcdefghij
this is the last record
그림 14 – 전체 파일
파일이 있는지 확인하는 것만으로는 충분하지 않으며 파일이 잠겨 있는지 확인해야 합니다(그림 15).
&attach_input
&label AGAIN
&if (exists new_file) = 1 & (locked new_file) = 0 &then &goto FTP
display_line new_file not ready for transfer as of (time)
sleep -seconds 15
&goto AGAIN
&
&
&label FTP
ftp 172.16.1.116
put new_file
&if (command_status) = 226 &then ..display_line OK
&else &do
..display_line
..display_line ERROR
..display_line
&end
quit
그림 15 – ftp5.cm - 파일을 전송하기 전에 파일이 잠금 해제되어 있는지 확인
따라서 가장 좋은 방법은 .netrc 파일을 사용하여 사용자 ID와 암호를 보관하고 VOS 명령 매크로를 사용하여 각 요청 후 command_status 확인할 수 있습니다. 또한 파일 검사를 전송하기 전에 잠겨 있지 않은지 확인합니다.
여러분 중 일부는 SFTP에 대해 궁금해합니다. SFTP로 파일 전송을 자동화하는 것은 완전히 다르며 다음 블로그에서 논의될 것입니다.

© 2024 스트라투스 테크놀로지스.