我想登录到ftp服务器(不是公共URL)并下载一个位于zip文件中的csv文件,然后将其保存到特定目录:
#log in OK
# this is the zip file I want to download
fpath = strDate + ".zip"
#set where to save file
ExtDir = "A:\\LOCAL\\DIREC\\TORY\\"""
ExtDir = ExtDir + strdate + "\\"
ExtFile = ExtDir + "Download.zip"
#download files
#use zipfile.ZipFile as alternative method to open(ExtFile, 'w')
with zipfile.ZipFile(ExtFile,'w') as outzip:
ftp.retrbinary('RETR %s' % fpath , outzip.write)
outzip.close
我收到此错误
文件" C:\ Program Files(x86)\ Python 2.7 \ lib \ ftplib.py",第419行,在retrbinary回调(数据)中 文件" C:\ Program Files(x86)\ Python 2.7 \ lib \ zipfile.py",第1123行,写入st = os.stat(文件名) TypeError:stat()参数1必须是没有空字节的编码字符串,而不是str
答案 0 :(得分:0)
修正使用:
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TreeItem;
public class testTitleDialog extends TitleAreaDialog {
private static final String DIALOG_TITLE = "TITLE AREA DIALOG";
Composite area;
public testTitleDialog(Shell parentShell) {
super(parentShell);
}
@Override
public void create() {
super.create();
setTitle("TITLE WILL BE HERE");
}
@Override
protected Control createDialogArea(final Composite parent) {
this.area = (Composite) super.createDialogArea(parent);
parent.getShell().setText(DIALOG_TITLE);
Composite area = (Composite) super.createDialogArea(parent);
Composite contents = (Composite) super.createDialogArea(area);
contents.setLayout(new GridLayout());
contents.setLayoutData(new GridData(GridData.FILL_BOTH));
contents.addDisposeListener(new DisposeListener(){
public void widgetDisposed(DisposeEvent e) {
}
});
createMapperComposite(contents);
return this.dialogArea;
}
private void createMapperComposite(Composite composite) {
Composite main = new Composite(composite, SWT.NONE);
main.setLayout(new GridLayout());
main.setLayoutData(new GridData(GridData.FILL_BOTH));
treeMapper(main);
}
private Composite treeMapper(Composite main) {
SashForm sashForm = new SashForm(main, SWT.HORIZONTAL);
Composite composite = new Composite(sashForm, SWT.NONE);
composite.setLayout(new GridLayout());
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
composite.setBackground(ColorConstants.white);
//i is number of trees
for (int i = 0; i < 10; i++) {
Label lbl = new Label(composite, SWT.NONE);
lbl.setText("Tree " + i);
// Add content to scrolled composite
Composite scrolledContent = new Composite(composite, SWT.NONE);
scrolledContent.setLayout(new GridLayout());
GridData gridData = new GridData();
gridData.horizontalAlignment = SWT.FILL;
gridData.grabExcessHorizontalSpace = true;
gridData.verticalAlignment = SWT.FILL;
gridData.grabExcessVerticalSpace = true;
scrolledContent.setLayoutData(gridData);
final TreeViewer tree = new TreeViewer(scrolledContent);
for(int loopIndex0 = 0; loopIndex0 < 10; loopIndex0++) {
TreeItem treeItem0 = new TreeItem(tree.getTree(), 0);
treeItem0.setText("Level 0 Item "+ loopIndex0);
for(int loopIndex1 = 0; loopIndex1 < 10; loopIndex1++) {
TreeItem treeItem1 = new TreeItem(treeItem0, 0);
treeItem1.setText("Level 1 Item "+ loopIndex1);
for(int loopIndex2 = 0; loopIndex2 < 10; loopIndex2++) {
TreeItem treeItem2 = new TreeItem(treeItem1, 0);
treeItem2.setText("Level 2 Item "+ loopIndex2);
}
}
}
tree.getTree().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
}
new TreeViewer(sashForm);
return main;
}
@Override
protected boolean isResizable() {
return true;
}
@Override
protected void okPressed() {
super.okPressed();
}
public static void main(final String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
new testTitleDialog(shell).open();
}