ChewToy ChewToy - 1 year ago 107
Bash Question

Python sys.argv out of range, don't understand why

I have a script that I've been using for a some time to easily upload files to my server. It has been working great for a long time, but I can't get it to work on my new desktop computer.

The code is simple:

import os.path
import sys
import os
from ftplib import FTP

host = ""
acc = ""
pw = ""
filepath = sys.argv[1]

if (not os.path.isfile(filepath)):
x = input("ERROR, invalid filepath")

filename = os.path.basename(filepath)
file_object = open(filepath, 'rb')

ftp = FTP(host)
ftp.login(acc, pw)
ftp.storbinary('STOR ' + filename, file_object)


I run it as: backup.sql

I get the following error:

Traceback (most recent call last):

File "C:\Users\Admin\Desktop\", line 12, in

filepath = sys.argv[1]

IndexError: list index out of range

I'm not sure why it's giving me an error that it can't find the first commandline argument even though I passed one to the script.

I am running Windows 7 64-bit with Python 2.7.2


Answer Source

Your .py association in the registry is incorrect. It's missing %* at the end.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download