File: ftp.html

package info (click to toggle)
erlang-doc-html 1%3A11.b.2-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 23,284 kB
  • ctags: 10,724
  • sloc: erlang: 505; ansic: 323; makefile: 62; perl: 61; sh: 45
file content (1085 lines) | stat: -rw-r--r-- 28,890 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
  <TITLE>ftp
</TITLE>
  <SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
  <STYLE TYPE="text/css">
<!--
    .REFBODY     { margin-left: 13mm }
    .REFTYPES    { margin-left: 8mm }
-->
  </STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
      ALINK="#FF0000">
<!-- refpage -->
<CENTER>
<A HREF="http://www.erlang.se">
  <IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif">
</A>
<H1>ftp
</H1>
</CENTER>

<H3>MODULE</H3>
<DIV CLASS=REFBODY>
ftp
</DIV>

<H3>MODULE SUMMARY</H3>
<DIV CLASS=REFBODY>
A File Transfer Protocol client
</DIV>

<H3>DESCRIPTION</H3>
<DIV CLASS=REFBODY>

<P>The <CODE>ftp</CODE> module implements a client for file transfer
according to a subset of the File Transfer Protocol (see <A HREF="application_term.html#RFC">RFC</A> 959). Starting from inets version 4.4.1 the ftp client
will always try to use passive ftp mode and only resort to active
ftp mode if this fails. There is a mode option for open/[1,2,3]
where this default behavior may be changed. Also the mode option
replaces the API function force_active/1 that now has become
deprecated. (force_active/1 is removed from the documentation but
is still available in the code for now.)
<P>For a simple example of an ftp session see <A HREF="ftp_client.html">Inets User's Guide.</A> 
<P>In addition to the ordinary functions for receiving and sending
files (see <CODE>recv/2</CODE>, <CODE>recv/3</CODE>, <CODE>send/2</CODE> and
<CODE>send/3</CODE>) there are functions for receiving remote files as
binaries (see <CODE>recv_bin/2</CODE>) and for sending binaries to to be
stored as remote files (see <CODE>send_bin/3</CODE>).
<P>There is also a set of functions for sending and receiving
contiguous parts of a file to be stored in a remote file (for send
see <CODE>send_chunk_start/2</CODE>, <CODE>send_chunk/2</CODE> and
<CODE>send_chunk_end/1</CODE> and for receive see
<CODE>recv_chunk_start/2</CODE> and <CODE>recv_chunk/</CODE>).
<P>The particular return values of the functions below depend very
much on the implementation of the FTP server at the remote host. In
particular the results from <CODE>ls</CODE> and <CODE>nlist</CODE> varies. Often
real errors are not reported as errors by <CODE>ls</CODE>, even if for
instance a file or directory does not exist. <CODE>nlist</CODE> is usually
more strict, but some implementations have the peculiar behaviour of
responding with an error, if the request is a listing of the
contents of directory which exists but is empty.
</DIV>

<H3> COMMON DATA TYPES </H3>
<DIV CLASS=REFBODY>

<P> Here follows type definitions that are used by more than one
function in the FTP client API. 
<PRE>
 pid() - identifier of an ftp connection.
</PRE>

<PRE>
 string() = list of ASCII characters
</PRE>

<PRE>
 shortage_reason() = etnospc | epnospc 
</PRE>

<PRE>
 restriction_reason() = epath | efnamena | elogin | enotbinary
     - note not all restrictions may always relevant to all functions
    
</PRE>

<PRE>
 common_reason() = econn | eclosed | term() - some kind of
                 explanation of what went wrong
</PRE>

</DIV>

<H3>EXPORTS</H3>

<P><A NAME="account/2"><STRONG><CODE>account(Pid, Account) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Account = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = eacct | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>If an account is needed for an operation set the account
         with this operation.
        
</DIV>

<P><A NAME="append/3"><STRONG><CODE>append(Pid, LocalFile [, RemoteFile]) -&#62; ok | {error,
Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>LocalFile = RemoteFile = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = epath | elogin | etnospc | epnospc | efnamena | common_reason</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Transfers the file <CODE>LocalFile</CODE> to the remote server. If 
        <CODE>RemoteFile</CODE> is specified, the name of the remote file that the
         file will be appended to is set to <CODE>RemoteFile</CODE>; otherwise 
         the name is set to <CODE>LocalFile</CODE> If the file does not exists the
         file will be created.

</DIV>

<P><A NAME="append_bin/3"><STRONG><CODE>append_bin(Pid, Bin, RemoteFile) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Bin = binary()()</CODE></STRONG><BR>
<STRONG><CODE>RemoteFile = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason()| shortage_reason() |
         common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Transfers the binary <CODE>Bin</CODE> to the remote server and append 
         it to the file <CODE>RemoteFile</CODE>. If the file does not exists it 
         will be created.

</DIV>

<P><A NAME="append_chunk/2"><STRONG><CODE>append_chunk(Pid, Bin) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Bin = binary()</CODE></STRONG><BR>
<STRONG><CODE>Reason = echunk | restriction_reason() | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Transfer the chunk <CODE>Bin</CODE> to the remote server, which 
        append it into the file specified in the call to 
        <CODE>append_chunk_start/2</CODE>. 
        
<P>Note that for some errors, e.g. file system full, it is 
neccessery to to call <CODE>append_chunk_end</CODE> to get the 
proper reason.

</DIV>

<P><A NAME="append_chunk_start/2"><STRONG><CODE>append_chunk_start(Pid, File) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>File = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Start the transfer of chunks for appending to the file 
         <CODE>File</CODE> at the remote server. If the file does not exists 
         it will be created.

</DIV>

<P><A NAME="append_chunk_end/1"><STRONG><CODE>append_chunk_end(Pid) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Reason = echunk | restriction_reason() | shortage_reason() </CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Stops transfer of chunks for appending to the remote server. 
         The file at the remote server, specified in the call to 
         <CODE>append_chunk_start/2</CODE> is closed by the server.

</DIV>

<P><A NAME="cd/2"><STRONG><CODE>cd(Pid, Dir) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Dir = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason() </CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Changes the working directory at the remote server to <CODE>Dir</CODE>.

</DIV>

<P><A NAME="close/1"><STRONG><CODE>close(Pid) -&#62; ok</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Ends the ftp session.

</DIV>

<P><A NAME="delete/2"><STRONG><CODE>delete(Pid, File) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>File = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Deletes the file <CODE>File</CODE> at the remote server.

</DIV>

<P><A NAME="formaterror/1"><STRONG><CODE>formaterror(Tag) -&#62; string()</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Tag = {error, atom()} | atom()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Given an error return value <CODE>{error, AtomReason}</CODE>,
         this function returns a readable string describing the error.

</DIV>

<P><A NAME="lcd/2"><STRONG><CODE>lcd(Pid, Dir) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Dir = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Changes the working directory to <CODE>Dir</CODE> for the local client. 

</DIV>

<P><A NAME="lpwd/1"><STRONG><CODE>lpwd(Pid) -&#62; {ok, Dir}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns the current working directory at the local client.

</DIV>

<P><A NAME="ls/2"><STRONG><CODE>ls(Pid [, Dir]) -&#62; {ok, Listing} | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Dir = string()</CODE></STRONG><BR>
<STRONG><CODE>Listing = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns a listing of the contents of the remote current directory
        (<CODE>ls/1</CODE>) or the specified directory (<CODE>ls/2</CODE>). The format
        of <CODE>Listing</CODE> is operating system dependent (on UNIX it is 
        typically produced from the output of the <CODE>ls -l</CODE> shell command).

</DIV>

<P><A NAME="mkdir/2"><STRONG><CODE>mkdir(Pid, Dir) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Dir = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Creates the directory <CODE>Dir</CODE> at the remote server.

</DIV>

<P><A NAME="nlist/2"><STRONG><CODE>nlist(Pid [, Dir]) -&#62; {ok, Listing} | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Dir = string()</CODE></STRONG><BR>
<STRONG><CODE>Listing = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns a listing of the contents of the remote current directory
        (<CODE>nlist/1</CODE>) or the specified directory
        (<CODE>nlist/2</CODE>). The format of <CODE>Listing</CODE> is a stream of
        file names, where each name is separated by &#60;CRLF&#62; or
        &#60;NL&#62;. Contrary to the <CODE>ls</CODE> function, the purpose of
        <CODE>nlist</CODE> is to make it possible for a program to
        automatically process file name information.

</DIV>

<P><A NAME="open/3"><STRONG><CODE>open(Host [, Port] [, Flags]) -&#62; {ok, Pid} | {error, Reason}</CODE></STRONG></A><BR>
<A NAME="open/2"><STRONG><CODE>open({option_list, Option_list}) -&#62; {ok, Pid} | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Host = string() | ip_address()</CODE></STRONG><BR>
<STRONG><CODE>ip_address() = {byte(), byte(), byte(), byte()}
         {byte(), byte(), byte(), byte(), byte(), byte(), byte(), byte()}
        </CODE></STRONG><BR>
<STRONG><CODE>byte() = 0 | 1 | ... | 255</CODE></STRONG><BR>
<STRONG><CODE>Port = integer()</CODE></STRONG><BR>
<STRONG><CODE>Flags = [Flag]</CODE></STRONG><BR>
<STRONG><CODE>Flag = verbose | debug | ip_v6_disabled</CODE></STRONG><BR>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Reason = ehost</CODE></STRONG><BR>
<STRONG><CODE>Option_list = [Options]</CODE></STRONG><BR>
<STRONG><CODE>Options = {host, Host} | {port, Port} | {mode, Mode} |
         {flags, Flags} | {timeout, Timeout} | {progress, ProgressOption}</CODE></STRONG><BR>
<STRONG><CODE>Mode = active | passive </CODE></STRONG><BR>
<STRONG><CODE>Timeout = integer()</CODE></STRONG><BR>
<STRONG><CODE>ProgressOption = ignore | {CBModule, CBFunction,
         InitProgress}</CODE></STRONG><BR>
<STRONG><CODE>CallBackModule = atom()</CODE></STRONG><BR>
<STRONG><CODE> CallBackFunction = atom()</CODE></STRONG><BR>
<STRONG><CODE> InitProgress = term()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Opens a session with the ftp server at <CODE>Host</CODE>. The argument
        <CODE>Host</CODE> is either the name of the host, its IP address in 
        dotted decimal notation (e.g. <CODE>&#34;150.236.14.136&#34;</CODE>), or a tuple
        of arity 4 (ipv4) or 8 (ipv6) (ex: <CODE>{150, 236, 14, 136}</CODE>).
         
        
<P>If <CODE>Port</CODE> is supplied, a connection is attempted using this 
         port number instead of the default (21).
         
        
<P>Default value for <CODE>Mode</CODE> is passive.
         
        
<P>If the atom <CODE>verbose</CODE> is included in <CODE>Flags</CODE>,
         response messages from the remote server will be written
         to standard output.

         
<P> The progress option is intended to be used by
         applications that want create some type of progress report
         such as a progress bar in a GUI. The default value for the
         progress option is ignore e.i. the option is not used. When
         the progress option is specified the following will happen
         when ftp:send/[3,4] or ftp:recv/[3,4] are called.
<P>
<UL>

<LI>
 Before a file is transfered the following call will
         be made to indicate the start of the file transfer and how big
         the file is. The return value of the callback function
         should be a new value for the UserProgressTerm that will
         bu used as input next time the callback function is
         called.
         
         
<PRE>
CBModule:CBFunction(InitProgress, File, {file_size, FileSize}) 
</PRE>

         
</LI>


<LI>
 Every time a chunk of bytes is transfered the
         following call will be made:
         
<PRE>
 CBModule:CBFunction(UserProgressTerm, File, {transfer_size, TransferSize}) 
</PRE>

         
</LI>


<LI>
 At the end of the file the following call will be
         made to indicate the end of the transfer.
         
<PRE>
 CBModule:CBFunction(UserProgressTerm, File, {transfer_size, 0}) 
</PRE>

         
</LI>


</UL>

<P> The callback function should be defined as 
<PRE>
CBModule:CBFunction(UserProgressTerm, File, Size) -&#62; UserProgressTerm
</PRE>

<PRE>
CBModule = CBFunction = atom()
</PRE>

<PRE>
UserProgressTerm = term()
</PRE>

<PRE>
File = string()
</PRE>

<PRE>
Size = {transfer_size, integer()} | {file_size, integer()} | {file_size, unknown}
</PRE>

<P> Alas for remote files it is not possible for ftp to
         determine the file size in a platform independent way. In
         this case the size will be <CODE>unknown</CODE> and it is
         left to the application to find out the size. 
<P>
<TABLE CELLPADDING=4>
  <TR>
    <TD VALIGN=TOP><IMG ALT="Note!" SRC="note.gif"></TD>
    <TD>

<P>The callback is made by a middleman process, hence the
         file transfer will not be affected by the code in the progress
         callback function. If the callback should crash this will be
         detected by the ftp connection process that will print an
         info-report and then go one as if the progress option was set
         to ignore.     </TD>
  </TR>
</TABLE>

<P>The file transfer type is set to the default of
        the FTP server when the session is opened. This is usually
        ASCCI-mode.
        
        
<P>The current local working directory (cf. <CODE>lpwd/1</CODE>) is
        set to the value reported by <CODE>file:get_cwd/1</CODE>. the wanted
        local directory.


<P>The timeout value is default set to 60000 milliseconds.
                 
        
<P>The return value <CODE>Pid</CODE> is used as a reference to the
        newly created ftp client in all other functions, and they should
        be called by the process that created the connection. The ftp
        client process monitors the process that created it and
        will terminate if that process terminates.

</DIV>

<P><A NAME="pwd/1"><STRONG><CODE>pwd(Pid) -&#62; {ok, Dir} | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason() </CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Returns the current working directory at the remote server.

</DIV>

<P><A NAME="recv/3"><STRONG><CODE>recv(Pid, RemoteFile [, LocalFile]) -&#62; ok |
        {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>RemoteFile = LocalFile = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason()
         | file_write_error_reason() </CODE></STRONG><BR>
<STRONG><CODE>file_write_error_reason() = see file:write/2</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Transfer the file <CODE>RemoteFile</CODE> from the remote server
         to the the file system of the local client. If
         <CODE>LocalFile</CODE> is specified, the local file will be
         <CODE>LocalFile</CODE>; otherwise it will be
         <CODE>RemoteFile</CODE>.
<P>If the file write failes
         (e.g. enospc), then the command is aborted and <CODE>{error,
         file_write_error_reason()}</CODE> is returned. The file is
         however <STRONG>not</STRONG> removed.
</DIV>

<P><A NAME="recv_bin/2"><STRONG><CODE>recv_bin(Pid, RemoteFile) -&#62; {ok, Bin} | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Bin = binary()</CODE></STRONG><BR>
<STRONG><CODE>RemoteFile = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Transfers the file <CODE>RemoteFile</CODE> from the remote server and 
        receives it as a binary.

</DIV>

<P><A NAME="recv_chunk_start/2"><STRONG><CODE>recv_chunk_start(Pid, RemoteFile) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>RemoteFile = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Start transfer of the file <CODE>RemoteFile</CODE> from the
        remote server.

</DIV>

<P><A NAME="recv_chunk/1"><STRONG><CODE>recv_chunk(Pid) -&#62; ok | {ok, Bin} | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Bin = binary()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Receive a chunk of the remote file (<CODE>RemoteFile</CODE> of 
<CODE>recv_chunk_start</CODE>). The return values has the following 
         meaning:
        
<P>
<UL>

<LI>
<CODE>ok</CODE> the transfer is complete.
</LI>


<LI>
<CODE>{ok, Bin}</CODE> just another chunk of the file.
</LI>


<LI>
<CODE>{error, Reason}</CODE> transfer failed.
</LI>


</UL>

</DIV>

<P><A NAME="rename/3"><STRONG><CODE>rename(Pid, Old, New) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>CurrFile = NewFile = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Renames <CODE>Old</CODE> to <CODE>New</CODE> at the remote server.

</DIV>

<P><A NAME="rmdir/2"><STRONG><CODE>rmdir(Pid, Dir) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Dir = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Removes directory <CODE>Dir</CODE> at the remote server.

</DIV>

<P><A NAME="send/3"><STRONG><CODE>send(Pid, LocalFile [, RemoteFile]) -&#62; ok |
        {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>LocalFile = RemoteFile = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason() |
         shortage_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Transfers the file <CODE>LocalFile</CODE> to the remote server. If 
        <CODE>RemoteFile</CODE> is specified, the name of the remote file is set
        to <CODE>RemoteFile</CODE>; otherwise the name is set to <CODE>LocalFile</CODE>.

</DIV>

<P><A NAME="send_bin/3"><STRONG><CODE>send_bin(Pid, Bin, RemoteFile) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Bin = binary()()</CODE></STRONG><BR>
<STRONG><CODE>RemoteFile = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason() |
         shortage_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Transfers the binary <CODE>Bin</CODE> into the file <CODE>RemoteFile</CODE> 
        at the remote server.

</DIV>

<P><A NAME="send_chunk/2"><STRONG><CODE>send_chunk(Pid, Bin) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Bin = binary()</CODE></STRONG><BR>
<STRONG><CODE>Reason = echunk | restriction_reason() | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Transfer the chunk <CODE>Bin</CODE> to the remote server, which 
        writes it into the file specified in the call to 
        <CODE>send_chunk_start/2</CODE>. 
        
<P>Note that for some errors, e.g. file system full, it is 
neccessery to to call <CODE>send_chunk_end</CODE> to get the 
proper reason.

</DIV>

<P><A NAME="send_chunk_start/2"><STRONG><CODE>send_chunk_start(Pid, File) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>File = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Start transfer of chunks into the file <CODE>File</CODE> at the 
        remote server.

</DIV>

<P><A NAME="send_chunk_end/1"><STRONG><CODE>send_chunk_end(Pid) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Reason = restriction_reason() | common_reason() |
         shortage_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Stops transfer of chunks to the remote server. The file at the
        remote server, specified in the call to <CODE>send_chunk_start/2</CODE> 
        is closed by the server.

</DIV>

<P><A NAME="type/2"><STRONG><CODE>type(Pid, Type) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Type = ascii | binary</CODE></STRONG><BR>
<STRONG><CODE>Reason = etype | restriction_reason() | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Sets the file transfer type to <CODE>ascii</CODE> or <CODE>binary</CODE>. When
        an ftp session is opened, the default transfer type of the
        server is used, most often <CODE>ascii</CODE>, which is the default
        according to RFC 959.

</DIV>

<P><A NAME="user/3"><STRONG><CODE>user(Pid, User, Password) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>User = Password = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = euser | common_reason()</CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Performs login of <CODE>User</CODE> with <CODE>Password</CODE>.

</DIV>

<P><A NAME="user/4"><STRONG><CODE>user(Pid, User, Password,Account) -&#62; ok | {error, Reason}</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>User = Password = string()</CODE></STRONG><BR>
<STRONG><CODE>Reason = euser | common_reason() </CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Performs login of <CODE>User</CODE> with <CODE>Password</CODE>to the acccount 
         specified by <CODE>Account</CODE> .

</DIV>

<P><A NAME="quote/2"><STRONG><CODE>quote(Pid, Command) -&#62; [FTPLine]</CODE></STRONG></A><BR>

<DIV CLASS=REFBODY><P>Types:
  <DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Pid = pid()</CODE></STRONG><BR>
<STRONG><CODE>Command = string()</CODE></STRONG><BR>
<STRONG><CODE>FTPLine = string() - Note the telnet end of line characters, from
         the ftp protocol definition, CRLF e.g. &#34;\r\n&#34; has been removed.
        </CODE></STRONG><BR>

  </DIV>
</DIV>

<DIV CLASS=REFBODY>

<P>Sends an arbitrary FTP command and returns verbatimly a list
        of the lines sent back by the FTP server. This functions is
        intended to give an application accesses to FTP commands
        that are server specific or that may not be provided by
        this FTP client. 

<P>
<TABLE CELLPADDING=4>
  <TR>
    <TD VALIGN=TOP><IMG ALT="Note!" SRC="note.gif"></TD>
    <TD>

<P>FTP commands that require a data connection can not be
successfully issued with this function.     </TD>
  </TR>
</TABLE>

</DIV>

<H3>ERRORS</H3>
<DIV CLASS=REFBODY>

<P>The possible error reasons and the corresponding diagnostic strings 
returned by <CODE>formaterror/1</CODE> are as follows:


<P>
<DL>

<DT>
<CODE>echunk</CODE>
</DT>

<DD>
Synchronisation error during chunk sending. 
         
        <BR>
A call has been made to <CODE>send_chunk/2</CODE> or
         <CODE>send_chunk_end/1</CODE>, before a call to
         <CODE>send_chunk_start/2</CODE>; or a call has been made to another
         transfer function during chunk sending, i.e. before a call
         to <CODE>send_chunk_end/1</CODE>.
<BR>

</DD>

<DT>
<CODE>eclosed</CODE>
</DT>

<DD>
The session has been closed.
<BR>

</DD>

<DT>
<CODE>econn</CODE>
</DT>

<DD>
Connection to remote server prematurely closed.
<BR>

</DD>

<DT>
<CODE>ehost</CODE>
</DT>

<DD>
Host not found, FTP server not found, or connection rejected
         by FTP server.
<BR>

</DD>

<DT>
<CODE>elogin</CODE>
</DT>

<DD>
User not logged in.
<BR>

</DD>

<DT>
<CODE>enotbinary</CODE>
</DT>

<DD>
Term is not a binary.
<BR>

</DD>

<DT>
<CODE>epath</CODE>
</DT>

<DD>
No such file or directory, or directory already exists, or
        permission denied.
<BR>

</DD>

<DT>
<CODE>etype</CODE>
</DT>

<DD>
No such type.
<BR>

</DD>

<DT>
<CODE>euser</CODE>
</DT>

<DD>
User name or password not valid.
<BR>

</DD>

<DT>
<CODE>etnospc</CODE>
</DT>

<DD>
Insufficient storage space in system [452].
<BR>

</DD>

<DT>
<CODE>epnospc</CODE>
</DT>

<DD>
Exceeded storage allocation (for current directory or
        dataset) [552].
<BR>

</DD>

<DT>
<CODE>efnamena</CODE>
</DT>

<DD>
File name not allowed [553].
<BR>

</DD>

</DL>

</DIV>

<H3>SEE ALSO</H3>
<DIV CLASS=REFBODY>

<P>file, filename, J. Postel and J. Reynolds: File Transfer Protocol
(RFC 959).


</DIV>

<H3>AUTHORS</H3>
<DIV CLASS=REFBODY>
Peter Hgfeldt - support@erlang.ericsson.se<BR>
Ingela Anderton Andin - support@erlang.ericsson.se<BR>

</DIV>
<CENTER>
<HR>
<SMALL>inets 4.7.6<BR>
Copyright &copy; 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>