FTP usage examples

FTP servers are accessed through the fs library and any method the library supports is available to Zato services as well.

Hence the code below serves as a set of examples only, it’s not a full reference.

Putting files on server

1
2
3
4
5
6
from zato.server.service import Service

class MyService(Service):
    def handle(self):
        conn = self.outgoing.ftp.get('My FTP')
        contents = conn.setcontents('/tmp/myfile', 'Hello\nFTP!\n')
$ cat /tmp/myfile
Hello
FTP!
$

Listing directories

1
2
3
4
5
6
7
from zato.server.service import Service

class MyService(Service):
    def handle(self):
        conn = self.outgoing.ftp.get('My FTP')
        listing = conn.listdir('/usr')
        self.logger.info(listing)
1
INFO - [u'bin', u'src', u'sbin', u'lib32', u'lib', u'share', u'include']

Reading files

$ cat /tmp/myfile
123
456
789
$
1
2
3
4
5
6
7
from zato.server.service import Service

class MyService(Service):
    def handle(self):
        conn = self.outgoing.ftp.get('My FTP')
        contents = conn.getcontents('/tmp/myfile')
        self.logger.info(contents)
INFO - 123
456
789