使用连字符的布料put()命令

时间:2013-10-31 13:46:20

标签: python fabric

我在将文件放到包含连字符(“ - ”)的服务器时遇到问题,我认为可能是因为Linux正在处理文件,但我不确定。该脚本正在扫描文件夹中的图片/项目,将它们放入列表中,然后将所有项目传输到服务器。

这是脚本的一部分:

def _transferContent(locale):
    ## Transferring images to server
    now = datetime.datetime.now()
    localImages = '/home/bcns/Pictures/upload/'
    localList = os.listdir(localImages)
    print("Found local items: ")
    print(localList)
    fname = "/tmp/backup_images_file_list"
    f = open(fname, 'r')
    remoteList = f.read()
    remoteImageLocation = "/var/www/bcns-site/pics/photos/backup_" + locale + "-" + `now.year` + `now.month` + `now.day` + "/"
    print("Server image location: " + remoteImageLocation)
    ## Checking local list against remote list (from the server)
    for localItem in localList:
        localItem_fullpath = localImages + localItem
        if os.path.exists(localItem_fullpath):
            if localItem in remoteList:
                print("Already exists: " + localItem)
            else:
                put(localItem_fullpath, remoteImageLocation)
        else:
            print("File not found: " + localItem)

这就是输出:

Directory created successfully
/tmp/bcns_deploy/backup_images_file_list
[<server>] download: /tmp/backup_images_file_list <- /tmp/bcns_deploy/backup_images_file_list

Warning: Local file /tmp/backup_images_file_list already exists and is being overwritten.

Found local items: 
['darth-vader-mug.jpg', 'gun-dog-leash.jpg', 'think-safety-first-sign.jpg', 'hzmp.jpg', 'cy-happ-short-arms.gif', 'Hogwarts-Crest-Pumpkin.jpg']
Server image location: /var/www/bcns-site/pics/photos/backup_fujitsu-20131031/
[<server>] put: /home/bcns/Pictures/upload/darth-vader-mug.jpg -> /var/www/bcns-site/pics/photos/backup_fujitsu-20131031/

Fatal error: put() encountered an exception while uploading '/home/bcns/Pictures/upload/darth-vader-mug.jpg'

Underlying exception:
    Failure

我试图去掉这些hyphons,然后传输工作正常。

服务器运行Ubuntu 12.04,客户端在ext3磁盘上运行Debian 7.1。

激怒错误,但是这里的任何人都知道可能导致此错误的线索?

1 个答案:

答案 0 :(得分:0)

Linux中命令行选项中的破折号,但文件名中间的破折号是文件。

检查文件权限 - 手动传输一个文件时,perms的设置可能与Fabric传输时不同。

我建议put()使用transfer a directory at a time。这将有助于确保所有文件(和权限)都是应该的。

示例(未经测试):

def _transferContent(locale):
    ## Transferring images to server
    now = datetime.datetime.now()
    localImageDir = '/home/bcns/Pictures/upload/'
    remoteImageDir = "/var/www/bcns-site/pics/photos/backup_" + locale + "-" + `now.year` + `now.month` + `now.day` + "/"
    print("Server image location: " + remoteImageDir)
    put( localImagesDir, remoteImageDir)